package edu.biwu.controller.resolver;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

@Component
@Log4j2(topic = "fileLogger")
public class MyExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        //错误信息输出到控制台
        System.out.println(handler);

        //错误信息输出到日志中
        log.error(handler+":"+ex.getMessage(),ex); //ex打印追踪信息

        //跳转到错误页面 相应给前端页面
        return new ModelAndView("error");
    }

}
